home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9344 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.PBI.net!usenet
  2. From: mich@pbinet.com
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Input into array of strings?
  5. Date: 9 Mar 1996 16:58:24 GMT
  6. Organization: Pacific Bell Internet Services
  7. Message-ID: <4hsdbg$efq@SNFC21_SRVR_WWW.PBI.net>
  8. References: <4hnv1e$o7n@rhea.glo.be>
  9. Reply-To: mich@pbinet.com
  10. NNTP-Posting-Host: ppp-5-36.rdcy01.pbinet.com
  11. X-Newsreader: IBM NewsReader/2 v1.03
  12.  
  13. In <4hnv1e$o7n@rhea.glo.be>, sclaeys@glo.be (Sven Claeys) writes:
  14. >i've got a structure
  15.  
  16. >struct ImmoData
  17. >{
  18. >   char code[3][5];
  19. >   ....
  20. >}....;
  21.  
  22. >now i want to read data from a file with fgets(...) into this array.
  23.  
  24. >I've tried
  25. >   for (i=0; i<5; i++)
  26. >       fgets(code[i],....);
  27. >or
  28. >   for (i=0; i<5; i++)
  29. >       fgets((char*) code[i], ...);
  30.  
  31. >but none of these seem to work. As i'm debugging the first code is
  32. >read correct, but the second is appended to the first and is also read
  33. >into the second, and so on.
  34.  
  35. >Could anyone help me with this strange phenomenon?
  36.  
  37. You can probably fix this by insuring all your substrings (or lines, or whatever
  38. you care to call them) are null terminated. Allocate (or simply declare) a char
  39. string of usable length (80 will be adequate, I'm sure), load the string into the
  40. buffer from the file, strlen the string, add one to the index, append a '/0', and
  41. voila. viola. (?)
  42.  
  43.